"""
# !/usr/bin/python3
@Date    : 2018-03-27 21:52:16
@Author  : zhangcaocao (zhangcaocao66@gmail.com)
@Website : http://little-rocket.cn/
"""

import matplotlib.pyplot as plt
import platform


def Help():
    print(platform.python_version())


Pointx = []
Pointy = []
Points_List = [[-4, 2], [2, 25], [6, 17], [11, 31]]
# print(Points_List[0][0])
Bx = []
By = []

Points_List_ = []

Bx_ = []
By_ = []
k = len(Points_List)


# print(k)


# (1-t)P[i] ** (k-1) + tP[i+1] ** (k-1)


def Build_Bezier(Point_0, Point_1, Point_2, Point_3, t):
    A_0 = (1 - t) ** 3
    A_1 = ((1 - t) ** 2) * 3 * t
    A_2 = (t ** 2) * (1 - t) * 3
    A_3 = t ** 3

    x = Point_0[0] * A_0 + Point_1[0] * A_1 + Point_2[0] * A_2 + Point_3[0] * A_3
    y = Point_0[1] * A_0 + Point_1[1] * A_1 + Point_2[1] * A_2 + Point_3[1] * A_3

    return [x, y]


def Draw():
    for t in range(1, 100):
        # t = t_/ 100
        Points_List_.append(Build_Bezier(Points_List[0], Points_List[1], Points_List[2], Points_List[3], t / 100))
        Bx_.append(Points_List_[t - 1][0])
        By_.append(Points_List_[t - 1][1])

    for k in range(len(Points_List)):
        Bx.append(Points_List[k][0])
        By.append(Points_List[k][1])

    plt.scatter(Bx, By, marker='x', s=100, c='red')
    plt.plot(Bx_, By_, c='g')
    plt.show()


if __name__ == '__main__':
    Draw()
